package a00800658.dbtool.util;

import java.util.Vector;

import javax.swing.table.DefaultTableModel;

@SuppressWarnings("serial")
public class RowDataTable extends DefaultTableModel {
	// if isReadOnly info is provided, then keep track of and disable editing to the columns that are read-only
	private Vector<Integer> readOnlyColumns;
	
	public RowDataTable() {
		super();
	}

	public RowDataTable(Vector<String> columnNames, int rowCount) {
		super(columnNames, rowCount);
	}
	
	public RowDataTable(Vector<Vector<String>> data, Vector<String> columnNames) {
		super(data, columnNames);
	}

	public boolean isCellEditable(int row, int column) {
		if(column == 0)
			return false;
		else if(readOnlyColumns != null){
			if(readOnlyColumns.contains(row))
				return false;
			else
				return true;
		}			
		else
			return true;
	}
		
	public void setReadOnlyColumns(Vector<Boolean> columnIsReadOnly){		
		if(columnIsReadOnly != null){
			if(readOnlyColumns == null)
				readOnlyColumns = new Vector<Integer>();
			else
				readOnlyColumns.removeAllElements();
			
			for(int i = 0; i < columnIsReadOnly.size(); i++){
				if(columnIsReadOnly.get(i) == true){
					readOnlyColumns.add(i);
				}
			}
		}
	}
	
	public void clearReadOnlyColumns(){
		readOnlyColumns.removeAllElements();
	}
}
